﻿using System;
using System.ComponentModel;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using Microsoft.SharePoint;
using Microsoft.SharePoint.WebControls;
using Microsoft.SharePoint.WebPartPages;
using System.Xml.Serialization;

namespace MetroPivotWebPart.WebParts.MetroPivotWebPart
{
    [ToolboxItemAttribute(false)]
    public class MetroPivotWebPart : System.Web.UI.WebControls.WebParts.WebPart
    {
        // Visual Studio might automatically update this path when you change the Visual Web Part project item.
        private const string _ascxPath = @"~/_CONTROLTEMPLATES/MetroPivotWebPart.WebParts/MetroPivotWebPart/MetroPivotWebPartUserControl.ascx";

        public MetroPivotWebPart()
        {
            ShowLastTab = true;
            HeadingFontSize = "220%";
        }

        protected override void CreateChildControls()
        {
            MetroPivotWebPartUserControl control = Page.LoadControl(_ascxPath) as MetroPivotWebPartUserControl;
            control.ShowLastTab = ShowLastTab;
            control.HeadingFontSize = HeadingFontSize;
            Controls.Add(control);
        }

        public override bool Hidden
        {
            get
            {
                return true;
            }
            set
            {
                base.Hidden = value;
            }
        }

        [Category("Metro Pivot Settings")]
        [DefaultValue(true)]
        [WebBrowsable(true)]
        [Personalizable(PersonalizationScope.Shared)]
        [FriendlyNameAttribute("Show Last Tab")]
        [Description("Track the last tab selected so it can be displayed upon return.")]
        [Browsable(true)]
        [XmlElement(ElementName = "ShowLastTab")]
        public bool ShowLastTab
        {
            get;
            set;
        }

        [Category("Metro Pivot Settings")]
        [DefaultValue(true)]
        [WebBrowsable(true)]
        [Personalizable(PersonalizationScope.Shared)]
        [FriendlyNameAttribute("Heading Font Size")]
        [Description("Set the size of the heading font. Default is 220%.")]
        [Browsable(true)]
        [XmlElement(ElementName = "HeadingFontSize")]
        public string HeadingFontSize
        {
            get;
            set;
        }
    }
}
